package com.desay.pangoo.itmt.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.desay.pangoo.common.lite.lang.web.CommonResponse;
import com.desay.pangoo.itmt.controller.vo.TechProjectStatusVo;
import com.desay.pangoo.itmt.controller.vo.TechProjectTopicVo;
import com.desay.pangoo.itmt.service.TechProjectStatusService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * 数据集
 *
 * @author uidq1163
 */
@RestController
@Api(tags = "ITMT Tech Project 课题状态变更管理")
@RequestMapping(value = "/techProject/status")
@Validated
public class TechProjectStatusController {
	@Autowired
	private TechProjectStatusService techProjectStatusService;

	@PostMapping
	@ApiOperation(value = "添加课题状态申请", notes = "添加课题状态申请")
	public ResponseEntity<Object> create(@Validated @RequestBody TechProjectStatusVo vo) {
		return new ResponseEntity<>(CommonResponse.success(techProjectStatusService.create(vo)), HttpStatus.OK);
	}

	@GetMapping(value = "topic")
	@ApiOperation(value = "获取所有课题关联项目信息", notes = "获取所有课题关联项目信息")
	public ResponseEntity<Object> getTopicList() {
		return new ResponseEntity<>(CommonResponse.success(techProjectStatusService.getAllTopicList()), HttpStatus.OK);
	}

	@PostMapping(value = "topic")
	@ApiOperation(value = "添加课题关联项目", notes = "添加课题关联项目")
	public ResponseEntity<Object> createTopic(@Validated @RequestBody TechProjectTopicVo vo) {
		return new ResponseEntity<>(CommonResponse.success(techProjectStatusService.createTopic(vo)), HttpStatus.OK);
	}

	@PutMapping(value = "topic/{id}")
	@ApiOperation(value = "更新课题关联项目信息", notes = "更新课题关联项目")
	public ResponseEntity<Object> updateTopic(@PathVariable(value = "id") Long id,
			@Validated @RequestBody TechProjectTopicVo vo) {
		techProjectStatusService.updateTopic(id, vo);
		return new ResponseEntity<>(CommonResponse.success(), HttpStatus.OK);
	}

	@GetMapping(value = "")
	@ApiOperation(value = "获取变更申请列表", notes = "获取变更申请列表")
	@ApiImplicitParams({ @ApiImplicitParam(name = "pageNo", type = "int", value = "指定查询页数", paramType = "query"),
			@ApiImplicitParam(name = "pageSize", type = "int", value = "每页数据数量", paramType = "query"),
			@ApiImplicitParam(name = "auditStatus", type = "int", value = "审核状态：1待审核，2审核通过，3审核不通过", paramType = "query"),
			@ApiImplicitParam(name = "taskStatus", type = "int", value = "审核状态：1待审核，2审核通过，3审核不通过", paramType = "query"),
			@ApiImplicitParam(name = "approvalStatus", type = "int", value = "技术状态：1待立项，2已立项，3结项待评审，4结项评审通过，5结项评审不通过", paramType = "query"),
			@ApiImplicitParam(name = "creator", value = "申请提出者（模糊查询）", dataTypeClass = String.class, paramType = "query"), })
	public ResponseEntity<Object> getAllList(@RequestParam(value = "creator", required = false) String creator,
			@RequestParam(value = "auditStatus", required = false) Integer auditStatus,
			@RequestParam(value = "taskStatus", required = false) Integer taskStatus,
			@RequestParam(value = "approvalStatus", required = false) Integer approvalStatus,
			@RequestParam(value = "pageNo", required = true, defaultValue = "1") Integer pageNo,
			@RequestParam(value = "pageSize", required = true, defaultValue = "10") Integer pageSize) {
		return new ResponseEntity<>(CommonResponse.success(
				techProjectStatusService.getList(pageSize, pageNo, auditStatus, taskStatus, approvalStatus, creator)),
				HttpStatus.OK);
	}

	@GetMapping(value = "{id}")
	@ApiOperation(value = "获取课题状态信息", notes = "获取课题状态信息")
	public ResponseEntity<Object> getInfoById(@PathVariable(value = "id") Long id) {
		return new ResponseEntity<>(CommonResponse.success(techProjectStatusService.getInfoById(id)), HttpStatus.OK);
	}
	
	@PutMapping(value = "{id}")
	@ApiOperation(value = "课题状态信息更新", notes = "课题状态信息更新")
	public ResponseEntity<Object> update(@PathVariable(value = "id") Long id,
			@Validated @RequestBody TechProjectStatusVo vo) {
		techProjectStatusService.update(id, vo);
		return new ResponseEntity<>(CommonResponse.success(), HttpStatus.OK);
	}

	@PutMapping(value = "audit/{id}")
	@ApiOperation(value = "技术定义审核", notes = "技术定义审核")
	public ResponseEntity<Object> audit(@PathVariable(value = "id") Long id,
			@Validated @RequestBody TechProjectStatusVo vo) {
		techProjectStatusService.audit(id, vo);
		return new ResponseEntity<>(CommonResponse.success(), HttpStatus.OK);
	}

	@PutMapping(value = "task/{id}")
	@ApiOperation(value = "任务书审核", notes = "任务书审核")
	public ResponseEntity<Object> task(@PathVariable(value = "id") Long id,
			@Validated @RequestBody TechProjectStatusVo vo) {
		techProjectStatusService.task(id, vo);
		return new ResponseEntity<>(CommonResponse.success(), HttpStatus.OK);
	}

	@PutMapping(value = "approval/{id}")
	@ApiOperation(value = "立项状态审核", notes = "立项状态审核")
	public ResponseEntity<Object> approval(@PathVariable(value = "id") Long id,
			@Validated @RequestBody TechProjectStatusVo vo) {
		techProjectStatusService.approval(id, vo);
		return new ResponseEntity<>(CommonResponse.success(), HttpStatus.OK);
	}
}
